
<template>
  <div class="mapWrapper">
    <div v-if="mark" class="mark"></div>
    <Tooltip v-if="label" class="labelTip" placement="top" :content="tip" :disabled="!tip" transfer>
      <div class="labelWrapper" :style="labelStyle"><span>{{label}}</span></div>
    </Tooltip>
    <slot name="prepend"></slot>
    <Row class-name="cellWrapper" @click.native="!disabled && $emit('select',editValue)">
      <template v-for="key in Object.keys(submitObj)">
        <Tag :key="key" v-if="!!editValue[submitObj[key] || key]">
          {{ lang[submitObj[key] || key] + editValue[submitObj[key] || key] }}
        </Tag>
      </template>
    </Row>
    <slot name="append"></slot>
    <Icon v-if="clearBtn" class="icon-clear" @click.stop="clear" type="ios-close-circle" size="16"/>
    <div v-if="addField" class="action" @click="$emit('addField')">+</div>
    <div v-if="removeField" class="action" @click="$emit('removeField')">-</div>
  </div>
</template>

<script>
export default {
  name: "cfg-pointer",
  model: {
    prop: 'value',
    event: 'change'
  },
  data() {
    return {
    }
  },
  computed:{
    clearBtn() {
      return this.clearable && !!Object.keys(this.editValue).length
    },
    editValue() {
      // console.log("file: cfg-pointer.vue:37  editValue  this.value:", this.value, this.submitObj)
      return this.value
    },
    lang(){
      return {
        "en-US": {
          id:'id:',
          nodeId:'node id:',
          parentId:'parentId:',
          type:'type:',
          className:'className:',
          category:'category:',
          name:'name:',
          nodeName: 'nodeName:',
        },
        "zh-CN": {
          id:'唯一标识:',
          nodeId:'节点id:',
          parentId:'上一级标识:',
          type:'类型:',
          className:'模型名称:',
          category:'分类:',
          name:'名称:',
          nodeName: '节点名称:',
        },
      }[this.G_Locale];
    },
  },
  mounted() {
    // this.editValue=this.value;
  },
  watch: {
    // value:function(newVal){
    //   this.editValue=newVal;
    // }
  },
  methods: {
    change(){
      this.$emit('change',this.editValue);
    },
    clear() {
      // this.$emit('select', {});
      this.$emit('clear')
    }
  },
  props:{
    // 在input中需要展示的字段
    submitObj: {
      default() {
        return {};
      }
    },
    value:{
      default:()=>{
        return {};
      }
    },
    labelStyle: {
      default: () => {
        return {};
      }
    },
    config: {
      default: () => {
        return {};
      }
    },
    disabled: {
      return: false
    },
    label: {
      default: () => {
        return '';
      }
    },
    tip: {
      default: () => {
        return null;
      }
    },
    addField: {
      default: () => {
        return false;
      }
    },
    removeField: {
      default: () => {
        return false;
      }
    },
    mark:{
      default: () => {
        return true;
      }
    },
    clearable:{
      default: () => {
        return false;
      }
    },
  },
}
</script>

<style scoped lang="less">
.icon-clear {
  cursor: pointer;
  position: absolute;
  right: 0;
  width: 32px;
  height: 32px;
  line-height: 32px;
  font-size: 16px;
  text-align: center;
  color: #808695;
  z-index: 3;
  // &:hover {
  //   background-color: #eee;
  // }
}
.mapWrapper {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  border-radius: 4px;
  background-color: #f7f7f7;
  margin:2px 0;
}
.labelWrapper {
  display: flex;
  height:32px;
  width:150px;
  justify-content: flex-end;
  align-items: center;
  padding: 0 8px;
  border: 1px solid #dcdee2;
  border-right:none;
  border-radius: 4px 0px 0px 4px;
  font-size: 14px;
  background-color: #f7f7f7;
}
.cellWrapper {
  position: relative;
  flex:1 1 auto;
  min-height:30px;
  padding:2px 4px;
  border: 1px solid #dcdee2;
  background-color: #ffffff;
  //border-left: none;
  border-radius: 0 4px 4px 0;
}
.labelTip {
  height:100%;
}
.editor {
  height:100%;
  flex:1 1 auto;
  border: none;
  padding:0;
}
.mark {
  width:5px;
  height:32px;
  background-color: var(--primary-color);
  border-color: var(--primary-color);
  margin-right:2px;
  opacity: 0.6;
}
.action {
  width:20px;
  margin-right: 5px;
  margin-left:5px;
  cursor: pointer;
  line-height: 2;
  text-align: center;
}
</style>